/**
 * dbms-sjtu
 * FieldInfo.java created at Aug 8, 2011
 */
package dbms.record;

/**
 * @author weapon
 *
 */
public class FieldInfo {
	public static final int USUAL = 0;
	public static final int NOTNULL = 1;
	public static final int PRIMARYKEY = 2;
	
	/**
	 * INT = 4,  VARCHAR = 12
	 */
	int type;
	int length;
	/**
	 * usual(0), not null(1), or primary key(2)
	 */
	int key; 
	
	Object defaultValue;
	
	public FieldInfo(int type, int length){
		this.type = type;
		this.length = length;
		this.key = USUAL;
	}
	
	public FieldInfo(int type, int length, int key){
		this.type = type;
		this.length = length;
		this.key = key;
	}
	
	/*public int calLengthByType(){
		if(this.type == 0){
			return 0;
		} else if(this.type == 4){
			return 4;
		} else if(this.type > 5){
			return (this.type - 5)/2;
		} else {
			Debug.Error("This field's type is wrong: " + this.type);
			return -1;
		}
	}
	
	public int calTypeByLength(){
		if(this.length == 0){
			return 0;
		} else if(this.length == 4){
			return 4;
		} else{
			return 2 * this.length + 5;
		}
	}*/
	
	public int getKey(){
		return key;
	}
	
	public void setKey(int key){
		this.key = key;
	}
	
	public int getType(){
		return type;
	}
	
	public void setType(int type){
		this.type = type;
	}
	
	public int getLength(){
		return length;
	}
	
	public void setLength(int length){
		this.length = length;
	}
}
